package com.yoga.utils;

/**
 * @author yan
 * @date 2025/8/8
 */

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 工具类，统一规范,相应格式
 */
@Data
@AllArgsConstructor
public class JsonResult<T> {
    private int code;
    private boolean success;
    private String msg;
    private T data;

    public static JsonResult<?> success() {
        return success(null);
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<>(200, true, "操作成功", data);
    }

    public static JsonResult<?> fail(int code, String msg) {
        return new JsonResult<>(code, false, msg, null);
    }

    public static JsonResult<?> fail(String msg) {
        return fail(500, msg);
    }
}
